package com.neusoft.ysu.npms.controller;


import com.neusoft.ysu.npms.pojo.Farmer;
import com.neusoft.ysu.npms.pojo.Help;
import com.neusoft.ysu.npms.pojo.Leader;
import com.neusoft.ysu.npms.pojo.Result;
import com.neusoft.ysu.npms.service.IHelpService;
import com.neusoft.ysu.npms.service.ILeaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：刘金秋
 * @since 2024-06-18
 */
@RestController
@RequestMapping("/leader")
public class LeaderController {
    @Autowired
    ILeaderService leaderService;

    @RequestMapping("/add")
    public Result add(@RequestBody Leader leader) {
//        System.out.println(department);
        leaderService.add(leader);
        return Result.success();
    }
    @RequestMapping("/delete")
    public Result deleteLeader(@RequestBody Leader leader) {
//        System.out.println(farmer);
        leaderService.deleteLeader(leader);
        return Result.success();
    }

    @RequestMapping("/update")
    public Result updateLeader(@RequestBody Leader leader){
        leaderService.updateLeader(leader);
        return Result.success();
    }

    @RequestMapping("getAll")
    public Result getAll(@RequestBody Leader leader,
                         @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                         @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize){
        return Result.success(leaderService.selectAll(leader,pageNum,pageSize));
    }

    @RequestMapping("findone")
    public Result findone(@RequestBody Leader leader){
        System.out.println(leader);
        leaderService.findById(leader);
        return Result.success();
    }
}
